Covid Tracker
Today's date: 2020-10-08 Database last date: 10/7/20
xxxxxxxxxx5
1
begin 2
_BASE_DIR = joinpath(, "..")3
push!(LOAD_PATH, joinpath(_BASE_DIR, ".."))4
using CovidTracker5
endxxxxxxxxxx1
1
df = download_covid_data();xxxxxxxxxx1
1
_SIZE = (690, 250); # plotsizeState Plots
Country plots
Europe
Latin America
A Comparison between Nordic Countries
xxxxxxxxxx5
1
begin 2
using FredData3
using Plots4
using DataFrames5
endxxxxxxxxxx3
1
# make sure you have your API key access set up 2
# https://github.com/micahjsmith/FredData.jl3
f = Fred();xxxxxxxxxx7
1
begin 2
# Quarterly real GDP at 2010 constant prices3
sweden_gdp = get_data(f, "CLVMNACSCAB1GQSE")4
denmark_gdp = get_data(f, "CLVMNACSCAB1GQDK")5
norway_gdp = get_data(f, "CLVMNACSCAB1GQNO")6
finland_gdp = get_data(f, "CLVMNACSCAB1GQFI")7
end;xxxxxxxxxx1
1
normalized_gdp_plots(range=20)xxxxxxxxxx1
1
normalized_gdp_plots(range=4)By not locking down, Sweden saved around 2% of GDP with respect to its neighbors in 2020 Q1.
xxxxxxxxxx1
1
# NOTE: norway quarterly GDP data may be off by a monthCost of life calculation
Sweden avoided the GDP drop of its neighbors in 2020Q1.
What if Sweden had the death rate of Norway, but GDP will have fallen as much as in Norway in the 2020Q2.? What's the GDP gain per unit of life lost?
xxxxxxxxxx4
1
begin 2
death_rate_NOR = total_deaths("Norway") / get_pop("NO")3
death_rate_SWE = total_deaths("Sweden") / get_pop("SE")4
end;xxxxxxxxxx25
1
begin2
# annual GDP for Sweden in current USD 3
annual_GDP_SWE_USD = get_data(f, "MKTGDPSEA646NWDB").data["value"][end]4
5
# quarterly value6
quarterly_GDP_SWE_USD = annual_GDP_SWE_USD / 47
8
# counter_factual_deaths if Sweden had Norway mortality rate9
counter_factual_deaths_saved_SWE = get_pop("SE") * 10
(death_rate_SWE - death_rate_NOR)11
12
idx_NOR = findfirst(13
x -> x >= Dates.Date(2020,01,01), 14
norway_gdp.data["date"]15
) 16
idx_SWE = findfirst(17
x -> x >= Dates.Date(2020,01,01), 18
sweden_gdp.data["date"]19
) 20
21
# counter factual GDP loss if Sweden GDP would have fallen in 2020 Q2 by the same22
# amount as Norway23
counter_factual_gdp_loss_SWE_USD = quarterly_GDP_SWE_USD *24
(1 - normalize(norway_gdp)[idx_NOR] / normalize(sweden_gdp)[idx_SWE])25
end;466818.0247820191xxxxxxxxxx1
1
value_of_life = counter_factual_gdp_loss_SWE_USD / counter_factual_deaths_saved_SWEThe counter factual value of life is USD 466,818.
Auxiliary functions
xxxxxxxxxx1
1
using Suppressornormalize (generic function with 1 method)xxxxxxxxxx4
1
function normalize(series; date=Dates.Date(2019,10, 1))2
idx = findfirst(x -> x >= date, series.data["date"]) 3
series.data["value"] / series.data["value"][idx]4
endnormalized_gdp_plots (generic function with 1 method)x
1
function normalized_gdp_plots(; range=20, legendpos=:bottom) 2
fig = plot(3
sweden_gdp.data["date"][end-range:end], 4
log.(normalize(sweden_gdp)[end-range:end]), 5
label="SWE", lw=2, marker=:auto, 6
legend=legendpos,7
title="Log Quarterly Real GDP, SA\n2019Q4 = 0")8
plot!(fig, 9
denmark_gdp.data["date"][end-range:end], 10
log.(normalize(denmark_gdp)[end-range:end]), 11
label="DNK", lw=2, marker=:auto)12
plot!(fig, 13
norway_gdp.data["date"][end-range:end], 14
log.(normalize(norway_gdp)[end-range:end]), 15
label="NOR", lw=2, marker=:auto)16
plot!(fig, 17
finland_gdp.data["date"][end-range:end], 18
log.(normalize(finland_gdp)[end-range:end]), 19
label="FIN", lw=2, marker=:auto)20
return fig21
endtotal_deaths (generic function with 1 method)xxxxxxxxxx7
1
function total_deaths(country)2
DATE_STR = r"^\d{1,2}\/\d{1,2}\/\d{2}$"3
return filter(x-> x["Country/Region"] === country, df[:global_deaths]) |>4
x -> x[!, DATE_STR] |>5
x -> mapcols(sum ∘ skipmissing, x) |>6
x -> x[end][1]7
end commas (generic function with 1 method)xxxxxxxxxx6
1
# https://stackoverflow.com/questions/52213829/in-julia-insert-commas-into-integers-for-printing-like-python-3-62
3
function commas(num::Integer)4
str = string(num)5
return replace(str, r"(?<=[0-9])(?=(?:[0-9]{3})+(?![0-9]))" => ",")6
endwith_terminal (generic function with 1 method)xxxxxxxxxx29
1
function with_terminal(f)2
local spam_out, spam_err3
false begin4
spam_out = begin5
spam_err = begin6
f()7
end8
end9
end10
spam_out, spam_err11
12
HTML("""13
<style>14
div.vintage_terminal {15
16
}17
div.vintage_terminal pre {18
color: #ddd;19
background-color: #333;20
border: 5px solid pink;21
font-size: .75rem;22
}23
24
</style>25
<div class="vintage_terminal">26
<pre>$(Markdown.htmlesc(spam_out))</pre>27
</div>28
""")29
end